package com.lyl.activiti.demo.test;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;

public class EventBasedGateway {
	@org.junit.Test
	public void test() {
		// 创建一个流程数据源的配置
		ProcessEngine processEngine = ProcessEngineConfiguration
				.createProcessEngineConfigurationFromResource(
						"deployment/activiti.cfg.xml").buildProcessEngine();
		// 获取数据源连接的服务
		RepositoryService repositoryService = processEngine
				.getRepositoryService();
		// 读取配置流程配置文件对象
		Deployment deployment = repositoryService.createDeployment()
				.addClasspathResource("deployment/EventBasedGateway.bpmn")
				.deploy();
		// 发布到数据库中
		ProcessDefinition pdf = repositoryService
				.createProcessDefinitionQuery()
				.deploymentId(deployment.getId()).singleResult();

		// 开启一个服务
		RuntimeService runtimeService = processEngine.getRuntimeService();
		TaskService taskService = processEngine.getTaskService();
		ProcessInstance pi = runtimeService
				.startProcessInstanceByKey("eventBasedGateway");
	}
}
